import unittest
import time
from function import *
from BSTestRunner import BSTestRunner

# 测试case的路径
test_dir = './test_case'
# 存放报告的路径
report_dir = './test_report/test_report_dir'

discover = unittest.defaultTestLoader.discover(test_dir, pattern='test*py')
# 报告命名时间格式化
now = time.strftime("%Y-%m-%d %H_%M_%S")
# 报告文件完整路径
report_name = report_dir + '/' + now + 'result.html'

# 打开文件在报告文件写入测试结果
with open(report_name, 'wb') as f:
    runner = BSTestRunner(stream=f, title="Test Report", description='test case result')
    runner.run(discover)
f.close()
latest_report = latest_report(report_dir)
print(latest_report)
send_email(latest_report)



